#include <iostream>
using namespace std;

class Base
{
public:
    virtual Base* clone(){
            return new Base();
    }
};
class Derived:public Base
{
public:
    virtual Derived* clone(){
            return new Derived();
    }
};
void foo(Base* pobj)
{
    Base* newObj = pobj->clone();
    Base* newObj2 = pobj->clone();
    Derived* p = dynamic_cast<Derived*>(newObj2);
    if(p){
        cout << "Good" << endl;
    }
    else{
        cout << "Error" << endl;
    }
}
int main()
{
    Base b;
    foo(&b);
    Derived d;
    foo(&d);
}

    
    
